export default {
	common: {
		baseUrl: "https://admin.yongzhengxs.cn/api",
		data: {},
		header: {
			"content-type": "application/x-www-form-urlencoded",
			"token": uni.getStorageSync('token') || ''
		},
		method: "GET"
	},
	request(options = {}) {
		uni.showLoading({
			title: '加载中'
		})
		options.url = this.common.baseUrl + options.url
		options.data = options.data || this.common.data
		options.header = options.header || this.common.header
		options.method = options.method || this.common.method
		return new Promise((res, rej) => {
			uni.request({
				...options,
				success: (result) => {
					// console.log(result.data.code, 'statusCode')
					setTimeout(() => {
						uni.hideLoading()
					}, 200)
					if (result.data.code == 200) {
						return res(result.data)
					} else {
						if (result.data.code == 401) {
							uni.removeStorageSync('token')
							uni.removeStorageSync('shopId')
							uni.navigateTo({
								url: '/pages/login'
							})
						}
						return rej(result.data)
					}
				}
			})
		})
	}
}